package com.chitang.common.registrar;

import com.chitang.common.config.MysqlSyncPluginConfig;
import com.chitang.common.listener.MysqlMqSyncListener;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author yicol
 * @version 1.0
 */
public class MysqlSyncPluginRegistrar
        implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {

    @Override
    public void setEnvironment(Environment environment) {

    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {

    }

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata,
                                        BeanDefinitionRegistry registry) {

        BeanDefinitionBuilder configBuilder = BeanDefinitionBuilder.genericBeanDefinition(MysqlSyncPluginConfig.class);
        registry.registerBeanDefinition(
                MysqlSyncPluginConfig.class.getSimpleName(),
                configBuilder.getBeanDefinition());

        BeanDefinitionBuilder listenerBuilder = BeanDefinitionBuilder.genericBeanDefinition(MysqlMqSyncListener.class);
        registry.registerBeanDefinition(
                MysqlMqSyncListener.class.getSimpleName(),
                listenerBuilder.getBeanDefinition());

    }


}
